package com.lvy.hczn.front.business.controller;

import java.util.List;

import com.lvy.hczn.front.system.domain.business.Pack;
import com.lvy.hczn.front.system.service.PackService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.common.core.page.TableDataInfo;

/**
 * 包装袋信息Controller
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@Controller
@RequestMapping("/system/pack")
@Slf4j
public class PackController extends BaseController {
    private String prefix = "system/pack";

    @Autowired
    private PackService packService;

    @RequiresPermissions("system:pack:view")
    @GetMapping()
    public String pack() {
        return prefix + "/pack";
    }

    /**
     * 查询包装袋信息列表
     */
    @RequiresPermissions("system:pack:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Pack pack) {
        startPage();
        List<Pack> list = packService.selectPackList(pack);
        return getDataTable(list);
    }

    /**
     * 导出包装袋信息列表
     */
    @RequiresPermissions("system:pack:export")
    @Log(title = "包装袋信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Pack pack) {
        List<Pack> list = packService.selectPackList(pack);
        ExcelUtil<Pack> util = new ExcelUtil<Pack>(Pack.class);
        return util.exportExcel(list, "包装袋信息数据");
    }

    /**
     * 新增包装袋信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存包装袋信息
     */
    @RequiresPermissions("system:pack:add")
    @Log(title = "包装袋信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Pack pack) {
        return toAjax(packService.insertPack(pack));
    }

    /**
     * 修改包装袋信息
     */
    @RequiresPermissions("system:pack:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Pack pack = packService.selectPackById(id);
        mmap.put("pack", pack);
        return prefix + "/edit";
    }

    /**
     * 修改保存包装袋信息
     */
    @RequiresPermissions("system:pack:edit")
    @Log(title = "包装袋信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Pack pack) {
        return toAjax(packService.updatePack(pack));
    }

    /**
     * 删除包装袋信息
     */
    @RequiresPermissions("system:pack:remove")
    @Log(title = "包装袋信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(packService.deletePackByIds(ids));
    }

    /**
     * 查询包装袋信息列表
     */
    @PostMapping("/sort/list")
    @ResponseBody
    public AjaxResult SortList(Pack pack) {
        List<Pack> list = packService.selectPackList(pack);
        return AjaxResult.success(list);
    }
}
